//服务端路径
let serverPath = "https://www.ghhlkj.com";
const $request = (url, data, method) => {
    return new Promise((resolve, reject) => {
        uni.showLoading({
            title: '加载中',
            icon: 'loading',
            mask: true
        });
        uni.request({
            url: serverPath + url,
            method: method,
            data: data,
            header:{
                // "authorization": uni.getStorageSync('token')
                "Content-type": "application/json"
            },
                
            success(res) {
                resolve(res)
                uni.hideLoading(); //关闭loading
            },
            fail(error) {
                reject(error);
                // throw new Error(error);
                uni.hideLoading(); //关闭loading
            },
            complete() {
                uni.hideLoading(); //关闭loading
            }
        })
    })
}
//get请求
const get = (url, data) => {
    return $request(url, data, 'GET')
}
//post请求
const post = (url, data) => {
    return $request(url, data, 'POST')
}


export default {
    post,
    get
}